package com.casa_apoio.conversores;

import java.util.Calendar;
import java.util.Date;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("numeroDiaria")
public class NumeroDiariasConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object value) {
        Date data = (Date) value;
        long dataEntrada = data.getTime();

        Calendar dataAtual = Calendar.getInstance();

        long diferenca = dataAtual.getTimeInMillis() - dataEntrada;

        int tempoDia = 1000 * 60 * 60 * 24;

        long diasDiferenca = diferenca / tempoDia;
                
        String diaria = String.valueOf(diasDiferenca + 1);
        return diaria;
    }

}
